﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//using Word = Microsoft.Office.Interop.Word;

namespace syc.Report
{
    public partial class ChanPin_SFC : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //private void Export()
        //{

        //    object miss = Type.Missing;
        //    object visible = true;
        //    object modify = false;
        //    string filepath = "/Report/Download/产成品收、发、存报表" + DateTime.Now.ToString("yyyyMMddHHmmffffff") + ".xls";
        //    object file = Server.MapPath(filepath);
        //    File.Copy(Server.MapPath("/Report/Templet/产成品收、发、存报表.xls"), (string)file, true);   

        //    Word.Application app = new Word.Application();

        //    Word.Document doc = app.Documents.Open(ref file, ref miss, ref modify, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref visible, ref miss, ref miss, ref miss, ref miss);
        //    doc.Activate();
        //    try
        //    {
        //        object replaceAll = Word.WdReplace.wdReplaceAll;

        //        app.Selection.Find.ClearFormatting();
        //        app.Selection.Find.Text = "#1#";

        //        app.Selection.Find.Replacement.ClearFormatting();
        //        app.Selection.Find.Replacement.Text = "124.32";

        //        app.Selection.Find.Execute(
        //        ref miss, ref miss, ref miss, ref miss, ref miss,
        //        ref miss, ref miss, ref miss, ref miss, ref miss,
        //        ref replaceAll, ref miss, ref miss, ref miss, ref miss);
        //        doc.Save();
        //    }
        //    catch (Exception e)
        //    {
        //        Response.Write(e.Message);
        //    }
        //    finally
        //    {
        //        doc.Close(ref miss, ref miss, ref miss);
        //        app.Application.Quit(ref miss, ref miss, ref miss);
        //        Response.Redirect(filepath);
        //    }
        //}

        private void Export()
        {
            string filepath = "/Report/Download/产成品收、发、存报表" + DateTime.Now.ToString("yyyyMMddHHmmffffff") + ".xls";
            string file = Server.MapPath(filepath);
            File.Copy(Server.MapPath("/Report/Templet/产成品收、发、存报表.xls"), (string)file, true);
            ExcelConnection exc = new ExcelConnection(file);
            exc.Open();
            exc.Update("[参数$]", "set [val]='2009年6月30日'", " where [var]='日期'");
            exc.Insert("[参数$]", "[var],[val]", "'a','b'","");
            exc.Insert("[参数$]", "[var],[val]", "'c','3265'", "");
            exc.Close();
            Response.Redirect(filepath);
        }
        protected void Button_Export_Click(object sender, EventArgs e)
        {
            //Response.Charset = "utf-8";
            //Response.ContentEncoding = System.Text.Encoding.UTF8;
            //Response.ContentType = "application/ms-word";
            //Response.AddHeader("content-disposition", "attachment; filename=\"Report.doc\"");
            //this.form1.Visible = false;
            Export();
        }

    }
}
